package xyz.erupt.flow.core.engine.Utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * Bean工具类
 */
@Component
public class BeanUtil {
    private final ApplicationContext applicationContext;

    @Autowired
    public BeanUtil(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    /**
     * 通过名称获取bean
     * @param beanName
     * @return
     */
    public Object getBeanByName(String beanName) {
        return applicationContext.getBean(beanName);
    }

    /**
     * 通过名称获取bean
     * @param beanName
     * @param clazz
     * @return
     * @param <T>
     */
    public <T> T getBeanByName(String beanName, Class<T> clazz) {
        return applicationContext.getBean(beanName, clazz);
    }
}
